<template>
  <div class="app-container">
    <ve-line :data="chartDatas" :settings="chartSettings"></ve-line>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公路名称"  prop="roadName">
        <el-select v-model="queryParams.roadName" placeholder="请选择公路">
          <el-option
            v-for="item in gongluList"
            :key="item.id + ''"
            :label="item.field2"
            :value="item.field2 + ''"
            :disabled="item.status == 1"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="隧道名称"  prop="tunnelName">
        <el-select v-model="queryParams.tunnelName" placeholder="请选择隧道">
          <el-option
            v-for="item in suidaoList"
            :key="item.id + ''"
            :label="item.field2"
            :value="item.field2 + ''"
            :disabled="item.status == 1"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="评定等级" prop="finalPclass">
        <el-input
          v-model="queryParams.finalPclass"
          placeholder="请输入最终评定等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="technicaltotalList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="totalId" />
      <el-table-column label="公路名称" align="center" prop="roadName" />
      <el-table-column label="隧道名称" align="center" prop="tunnelName" />
      <el-table-column label="管养单位" align="center" prop="maintenanceOrganization" />
      <el-table-column label="土建结构评定等级" align="center" prop="civilPclass" />
      <el-table-column label="机电设施等级" align="center" prop="jdPclass" />
      <el-table-column label="总体评分" align="center" prop="finalGrade" />
      <el-table-column label="总体评定等级" align="center" prop="finalPclass" />
      <el-table-column label="本次评定日期" align="center" prop="adjustData" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.adjustData, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCheck(scope.row)"
            v-hasPermi="['technicaltotal:technicaltotal:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="handleExport(scope.row)"
            v-hasPermi="['technicaltotal:technicaltotal:exportWord']"
          >导出</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />




    <!-- 查看总体技术状况评定对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px" >
        <el-col :span="12">
        <el-form-item label="公路名称" >
          <el-input v-model="form.roadName" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="隧道编码">
          <el-input v-model="form.tunnelId" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="隧道名称" >
          <el-input v-model="form.tunnelName"  />
        </el-form-item>
        </el-col>
          <el-col :span="12">
        <el-form-item label="管养单位">
          <el-input v-model="form.maintenanceOrganization" />
        </el-form-item>
          </el-col>
        <el-col :span="12">
        <el-form-item label="洞口最大值" prop="tunnelHoleMax">
          <el-input v-model="form.tunnelHoleMax"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="洞口权重" prop="tunnelHoleLimit">
          <el-input v-model="form.tunnelHoleLimit"/>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="洞门最大值" prop="tunnelDoorMax">
          <el-input v-model="form.tunnelDoorMax" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="洞门权重" prop="tunnelDoorLimit">
          <el-input v-model="form.tunnelDoorLimit"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="衬砌最大值" prop="liningMax">
          <el-input v-model="form.liningMax" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="衬砌权重" prop="linningLimit">
          <el-input v-model="form.linningLimit"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="路面最大值" prop="roadsurfaceMax">
          <el-input v-model="form.roadsurfaceMax"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="路面权重" prop="roadsurfaceLimit">
          <el-input v-model="form.roadsurfaceLimit"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="检修道最大值" prop="jianxiudaoMax">
          <el-input v-model="form.jianxiudaoMax"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="检修道权重" prop="jianxiudaoLimit">
          <el-input v-model="form.jianxiudaoLimit"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="排水设施最大值" prop="waterMax">
          <el-input v-model="form.waterMax"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="排水设施权重" prop="waterLimit">
          <el-input v-model="form.waterLimit"/>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="吊顶最大值" prop="topMax">
          <el-input v-model="form.topMax" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="吊顶权重" prop="topLimit">
          <el-input v-model="form.topLimit" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="装饰物最大值" prop="directMax">
          <el-input v-model="form.directMax"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="装饰物权重" prop="directLimit">
          <el-input v-model="form.directLimit" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="标志标线最大值" prop="markingMax">
          <el-input v-model="form.markingMax"/>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="标志标线权重" prop="markingLimit">
          <el-input v-model="form.markingLimit" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="土建结构评分评分" prop="civilGrade">
          <el-input v-model="form.civilGrade" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="土建结构评定等级" prop="civilPclass">
          <el-input v-model="form.civilPclass"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="机电设施评分" prop="jdGrade">
          <el-input v-model="form.jdGrade"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="机电设施等级" prop="jdPclass">
          <el-input v-model="form.jdPclass" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="最终评分" prop="finalGrade">
          <el-input v-model="form.finalGrade"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="最终评定等级" prop="finalPclass">
          <el-input v-model="form.finalPclass" />
        </el-form-item>
        </el-col>
        <el-form-item label="本次评定日期" >
          <el-date-picker clearable
                          v-model="form.adjustData"
                          type="date"
                          value-format="yyyy-MM-dd"
                         >
          </el-date-picker>
        </el-form-item>
        <el-col :span="12">
        <el-form-item label="评定人" >
          <el-input v-model="form.adjuster"  />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="记录人" >
          <el-input v-model="form.record"  />
        </el-form-item>
        </el-col>
        <el-col >
        <el-form-item label="养护措施建议" prop="suggest">
          <el-input
            v-model="form.suggest"
            type="textarea"
          />
        </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTechnicaltotal, getTechnicaltotal, delTechnicaltotal, addTechnicaltotal, updateTechnicaltotal ,exportWord} from "@/api/civil/technicaltotal";
import { listSuidao } from "@/api/biz/suidao";
import { listGonglu } from "@/api/biz/gonglu";
export default {
  name: "Technicaltotal",
  data() {
    this.chartSettings = {
    }
    return {
      chartData:[],
      chartDatas: {
        columns: ['隧道名称', '总体评分','土建结构评分','机电设施评分'],
        rows: [
        ]
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 总体技术状况评定表格数据
      technicaltotalList: [],
      //隧道表格数据
      suidaoList: [],
      //道路列表
      gongluList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openadd: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roadName: null,
        tunnelId: null,
        tunnelName: null,
        maintenanceOrganization: null,
        tunnelHoleMax: null,
        tunnelHoleLimit: null,
        tunnelDoorMax: null,
        tunnelDoorLimit: null,
        liningMax: null,
        linningLimit: null,
        roadsurfaceMax: null,
        roadsurfaceLimit: null,
        jianxiudaoMax: null,
        jianxiudaoLimit: null,
        waterMax: null,
        waterLimit: null,
        topMax: null,
        topLimit: null,
        directMax: null,
        directLimit: null,
        markingMax: null,
        markingLimit: null,
        civilGrade: null,
        civilPclass: null,
        jdGrade: null,
        jdPclass: null,
        finalGrade: null,
        finalPclass: null,
        adjustData: null,
        adjuster: null,
        record: null,
        suggest: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        tunnelName:[
          {required:true, message:"隧道名称为必填项", trigger:"blur"}
        ],
        tunnelId:[
          {required:true, message:"隧道编码为必填项", trigger:"blur"}
        ],
        roadName:[
          {required:true, message:"道路名称为必填项", trigger:"blur"}
        ],
        maintenanceOrganization:[
          {required:true, message:"管养单位为必填项", trigger:"blur"}
        ],
        adjustData:[
          {required:true, message:"检查日期为必填项", trigger:"blur"}
        ],
        adjuster:[
          {required:true, message:"评定人为必填项", trigger:"blur"}
        ],
        record:[
          {required:true, message:"记录人为必填项", trigger:"blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
    listSuidao({}).then((response) => {
      this.suidaoList = response.rows;
    });
    listGonglu({}).then((response) => {
      this.gongluList = response.rows;
    });
  },
  methods: {
    /** 查询总体技术状况评定列表 */
    getList() {
      this.loading = true;
      listTechnicaltotal(this.queryParams).then(response => {
        this.technicaltotalList = response.rows;
        this.total = response.total;
        this.chartData=response.rows;
        this.chartDatas.rows=[];
        for(var i =0;i<this.chartData.length;i++){
          this.chartDatas.rows.push({
            '隧道名称':i+1+this.chartData[i].tunnelName,
            '总体评分':this.chartData[i].finalGrade,
            '土建结构评分':this.chartData[i].civilGrade,
            '机电设施评分':this.chartData[i].jdGrade
          })
        }
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openadd = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        totalId: null,
        roadName: null,
        tunnelId: null,
        tunnelName: null,
        maintenanceOrganization: null,
        tunnelHoleMax: null,
        tunnelHoleLimit: null,
        tunnelDoorMax: null,
        tunnelDoorLimit: null,
        liningMax: null,
        linningLimit: null,
        roadsurfaceMax: null,
        roadsurfaceLimit: null,
        jianxiudaoMax: null,
        jianxiudaoLimit: null,
        waterMax: null,
        waterLimit: null,
        topMax: null,
        topLimit: null,
        directMax: null,
        directLimit: null,
        markingMax: null,
        markingLimit: null,
        civilGrade: null,
        civilPclass: null,
        jdGrade: null,
        jdPclass: null,
        finalGrade: null,
        finalPclass: null,
        adjustData: null,
        adjuster: null,
        record: null,
        suggest: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.totalId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openadd = true;
      this.title = "添加总体技术状况评定";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const totalId = row.totalId || this.ids
      getTechnicaltotal(totalId).then(response => {
        this.form = response.data;
        this.openadd = true;
        this.title = "修改总体技术状况评定";
      });
    },

    /** 查看详情按钮操作 */
    handleCheck(row) {
      this.reset();
      const totalId = row.totalId || this.ids
      getTechnicaltotal(totalId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看总体技术状况评定";
      });
    },


    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.totalId != null) {
            updateTechnicaltotal(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openadd = false;
              this.getList();
            });
          } else {
            addTechnicaltotal(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openadd = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const totalIds = row.totalId || this.ids;
      this.$modal.confirm('是否确认删除总体技术状况评定编号为"' + totalIds + '"的数据项？').then(function() {
        return delTechnicaltotal(totalIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },

    /** 导出按钮操作 */
    handleExport(row) {
      const totalId = row.totalId;
      this.$message({
        message: "导出成功",
        type: "success",
      });
      exportWord(totalId);
    },

  }
};
</script>
